//
//  CarAndBeautyViewController.m
//  TheRoadAD
//
//  Created by 宁宁 on 16/8/17.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "CarAndBeautyViewController.h"

#import "CarAndBeautyHeaderView.h"//搜索View
#import "TunerTableViewCell.h"//商家cell

#import "CarAndBeautyDetailViewController.h"//香车美女详情页Controller
#import "OthersHomePageViewController.h"//他人主页Controller

@interface CarAndBeautyViewController () <UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation CarAndBeautyViewController
{
    CarAndBeautyHeaderView *_headerView;
}

 static NSString *const TunerTableViewCellID = @"TunerTableViewCell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置导航栏
    [self setNav];
    
    //注册TableView
    [self registerTableView];
    
}
- (void)setNav{
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.title = @"香车美女";
    
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_home_meitu_1"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.leftBarButtonItem = back;
    
    UIBarButtonItem *more = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_pinpai"] style:UIBarButtonItemStylePlain target:self action:@selector(moreConditions)];
    self.navigationItem.rightBarButtonItem = more;
}

- (void)registerTableView{
    _headerView = [[[NSBundle mainBundle] loadNibNamed:@"CarAndBeautyHeaderView" owner:nil options:nil] lastObject];
    _headerView.frame = CGRectMake(0, 0, Screen_Width, 36);
    _headerView.search.delegate = self;
    self.tableView.tableHeaderView = _headerView;
    
    [self.tableView registerNib:[UINib nibWithNibName:@"TunerTableViewCell" bundle:nil] forCellReuseIdentifier:TunerTableViewCellID];
}

#pragma mark === TableViewDelegate ===
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100 + Screen_Width / 25 * 12;
}
//Reusable
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    TunerTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TunerTableViewCellID];
    [cell.firstBtn setTitle:@"我要拍" forState:UIControlStateNormal];
    [cell.firstBtn setImage:[UIImage imageNamed:@"icon_pai"] forState:UIControlStateNormal];
    cell.spacing.constant = 0;
    //    cell.headImg.image = [UIImage imageNamed:];
    //    cell.name.text =
    cell.pic.image = [UIImage imageNamed:[NSString stringWithFormat:@"icon_tu_%ld", indexPath.row % 3 + 1]];
    //    cell.picNum.text = [NSString stringWithFormat:@"%@图", ];
    cell.cellClick = ^(int temp){
        switch (temp) {
            case 0:
            {
                NSLog(@"我要拍");
            }
                break;
            case 1:
            {
                NSLog(@"评论");
            }
                break;
            case 2:
            {
                NSLog(@"分享");
            }
                break;
            case 3:
            {
                OthersHomePageViewController *others = [[OthersHomePageViewController alloc] init];
                others.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:others animated:YES];
            }
            default:
                break;
        }
    };
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;

}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    CarAndBeautyDetailViewController *car = [[CarAndBeautyDetailViewController alloc] init];
    car.index = 0;
    car.picArray = @[@"A.jpeg", @"B.jpeg", @"C.jpeg", @"D.jpeg", @"E.jpeg", @"F.jpeg"];
    car.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:car animated:YES];
}


//搜索
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    if (![textField.text isEqualToString:@""]) {
        NSLog(@"搜索");
    }
    [textField resignFirstResponder];
    return YES;
}

- (void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)moreConditions{
    
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0,0, Screen_Width, Screen_Height)style:UITableViewStylePlain];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorColor = [UIColor clearColor];
        _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
        [self.view addSubview:_tableView];
    }
    return _tableView;
}

@end
